import instance from './index';
import qs from 'qs';

const preUrlPath = '';
//获取委托订单列表-分页
const request = {
  p: ['api:user:fetch'],
  r: params => {
    return instance.get(`/v1/trade/fetchEntrustOrderPageList`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//获取完成订单列表-分页
const requestDeal = {
  p: ['api:user:fetch'],
  r: params => {
    return instance.get(`/v1/trade/fetchDealOrderPageList`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//添加委托订单
const add = {
  p: ['api:user:new'],
  r: params => {
    return instance.post(`/v1/trade/createEntrustOrder`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//获取委托订单信息
const info = {
  p: ['get'],
  r: params => {
    return instance.get(`/v1/coin/info`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//获取最近成交记录
const requestRecentDeal = {
  p: ['get'],
  r: params => {
    return instance.get(`/v1/trade/fetchRecentlyDealList`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//获取最近的委托买单和卖单
const requestRecentEntrust = {
  p: ['api:user:modify'],
  r: params => {
    return instance.post(`/v1/trade/fetchRecentlyEntrustList`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//计算总额
const caculate = {
  p: ['get'],
  r: params => {
    return instance.get(`/v1/trade/caculate`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//取消委托订单
const cancel = {
  p: ['api:user:modify'],
  r: params => {
    return instance.post(`/v1/trade/cancelEntrustOrder`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//获取交易区列表--系统业务配置列表
const areaList = {
  p: ['get'],
  r: params => {
    return instance.get(`/v1/cfg/fetchConfigList`, {params}).catch(function(res){
      console.log(res)
    })
  }
};

//越权请求
const notAllowed = {
  p: ['get,/roles/notAllowed'],
  r: params => {
    return instance.get(`${preUrlPath}/GET/roles/notAllowed`, {params})
  }
}

export {
  request,
  notAllowed,
  add,
  cancel,
  info,
  requestDeal,
  requestRecentDeal,
  requestRecentEntrust,
  caculate,
  areaList
}
